var jf = '/api'
const api = 'http://api.octaut.com'
   
const request = (urlType= '', url = '', type = '', date = {}, header = {
}) => {
	var that = this
    return new Promise((resolve, reject) => {
		uni.showLoading({
		    title: '加载中...'
		});
        uni.request({
            method: type,
            url: api + url,
            data: date,
            header: {
				'content-type': 'application/x-www-form-urlencoded',
				'token': uni.getStorageSync('token')
				},
            dataType: 'json'         
        }).then((response) => {
			uni.hideLoading();
			// console.log(response)
			if (response[1].data.code == 401) {
				uni.showToast({
				    title: response[1].data.msg,
					icon: 'error',
				    duration: 2000
				});
				uni.removeStorageSync('token');
				uni.navigateTo({
					url:'/pages/login/index'
				})
			}
			if (response[1].data.code != 0) {
				let [error, res] = response;
				resolve(res.data);
			} else {
				uni.showToast({
				    title: response[1].data.msg,
					icon: 'error',
				    duration: 2000
				});
			}
        }).catch(error => {
            let [err, res] = error;
            reject(err)
			console.log(error[1].data)
			uni.showToast({
			    title: error,
				icon: 'none',
			    duration: 2000
			});
        })
    });
	
}
export default request